package test.test.one.objects;

import android.graphics.Bitmap;
import android.graphics.Canvas;

/**
 * @author Gustavo
 *
 * AbstractObject is an abstract class used to create all world objects
 */
public abstract class AbstractObject {
	
	/*
	 * first declarations
	 */
	protected Bitmap bitmap;
	protected int x,y;
	protected boolean touched;
	
	/**
	 * AbstractObject constructor method
	 * 
	 * @param bitmap, sprite image
	 * @param x, initial x-axis position
	 * @param y, initial y-axis position
	 */
	public AbstractObject(Bitmap bitmap, int x, int y){
		this.bitmap = bitmap;
		this.x = x;
		this.y = y;
	}
	
	/*
	 * set & get methods
	 */
	
	public Bitmap getBitmap() {
		return bitmap;
	}
	public void setBitmap(Bitmap bitmap) {
		this.bitmap = bitmap;
	}
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	public boolean isTouched() {
		return touched;
	}
	public void setTouched(boolean touched) {
		this.touched = touched;
	}
	
	/*
	 * draw method
	 */
	
	public void draw(Canvas canvas) {
		canvas.drawBitmap(bitmap, x - (bitmap.getWidth() / 2), y - (bitmap.getHeight() / 2), null);
	}
	
	/**
	 * Method that will define an object's behavior when touched
	 * In this case, it sets touched boolean variable as true
	 * 
	 * @param eventX X-coordinate
	 * @param eventY Y-coordinate
	 */
	public void handleActionDown(int eventX, int eventY) {
		if (eventX >= (x - bitmap.getWidth() / 2) && (eventX <= (x + bitmap.getWidth() /2 ))) 
			if (eventY >= (y - bitmap.getHeight() / 2) && (eventY <= (y + bitmap.getHeight() /2 ))) {
				setTouched(true);
				return;
			}			 
			setTouched(false);
		}
}
